package drds.server.execute_engine.data_handling;

/**
 * column ->node index
 */
public class Value {
	public Integer nodeIndex;
	/**
	 * 只支持一个具体的值和范围的值,其他情况不支持。其好处是简单,其难度是进行统计和复杂的查询不可以。
	 */
	public final String columnValue;
	public final RangeValue rangeValue;

	public Value(String columnValue) {
		super();
		this.columnValue = columnValue;
		this.rangeValue = null;
	}

	public Value(RangeValue rangeValue) {
		super();
		this.rangeValue = rangeValue;
		this.columnValue = null;
	}

	public Integer getNodeIndex() {
		return nodeIndex;
	}

	public void setNodeIndex(Integer nodeIndex) {
		this.nodeIndex = nodeIndex;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((columnValue == null) ? 0 : columnValue.hashCode());
		result = prime * result + ((rangeValue == null) ? 0 : rangeValue.hashCode());
		result = prime * result + ((nodeIndex == null) ? 0 : nodeIndex.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) {
			return true;
		}
		if (o == null) {
			return false;
		}
		if (getClass() != o.getClass()) {
			return false;
		}
		Value other = (Value) o;
		if (columnValue == null) {
			if (other.columnValue != null) {
				return false;
			}
		} else if (!columnValue.equals(other.columnValue)) {
			return false;
		}

		if (rangeValue == null) {
			if (other.rangeValue != null) {
				return false;
			}
		} else if (!rangeValue.equals(other.rangeValue)) {
			return false;
		}

		if (nodeIndex == null) {
			if (other.nodeIndex != null) {
				return false;
			}
		} else if (!nodeIndex.equals(other.nodeIndex)) {
			return false;
		}
		return true;
	}
}